#ifndef GRAPHVIEW_H
#define GRAPHVIEW_H

#include"Vertex.h"
#include"Edge.h"
#include<QVector>
#include<QGraphicsView>
#include<QGraphicsScene>
#include<QMouseEvent>
#include<cmath>
#include<Eigen/Geometry>

const int inf=1000;
using namespace Eigen;

class GraphView:public QGraphicsView
{
    Q_OBJECT
private:
    void mousePressEvent(QMouseEvent *event);
    //void mouseMoveEvent(QMouseEvent *event);

    qreal adj[inf][inf];

public:
    GraphView(QWidget* parent);
    QGraphicsScene* scene;
    Vertex* vertex[inf];
    Edge* edge[inf];
    int EdgeCount;
    int state=0;
    Vertex* start;
    Vertex* end;
    Matrix<qreal,Dynamic,Dynamic> A;
    Matrix<qreal,Dynamic,Dynamic> G;
    Matrix<qreal,Dynamic,Dynamic> G_n;
    Matrix<qreal,Dynamic,1> U_n;
    Matrix<qreal,Dynamic,1> I_s;
    Matrix<qreal,Dynamic,1> U_s;

    bool SameVex(QPointF x,QPointF y);
    void AddVex(QPointF ScePos);
    void DelVex(Vertex* TempVex);
    void AddArc(Vertex* TempStart,Vertex* TempEnd);
    void DelArc(Edge* TempEdge);
    void UpdateA();
    void UpdateG();
    void UpdateU_s();
    void UpdateI_s();
    void solve();
    void init();
    Edge* HasConnection(Vertex* a,Vertex* b);
    void ParSim();
};

#endif // GRAPHVIEW_H
